#! /usr/bin/python

def isly(n):
    '''return True if n can become a palindrome in less than 50 iterations of reversing and adding.
    '''
    itrs = 0
    rn = int(str(n)[::-1])
    while itrs < 50:
        #print 'itr:' + str(itrs) + ':\t' + str(n) + '+' + str(rn) + '=' + str(n+rn)
        n = n + rn
        rn = int(str(n)[::-1])
        if n == rn:
            return False
        itrs += 1
    return True

def main():
    count = 0
    for n in range(1,10000):
        if isly(n):
            count += 1
    print count

if __name__ == '__main__':
    main()
    
